import unittest

# 创建testloader对象
# 模块名加载
loader1 = unittest.defaultTestLoader.loadTestsFromName('test_cases.test_demo1')
# 类名加载
loader2 = unittest.defaultTestLoader.loadTestsFromName('test_cases.test_demo2.DemoTestCase2')
# 方法名专加载
loader3 = unittest.defaultTestLoader.loadTestsFromName('test_cases.test_demo1.DemoTestCase1.test001')
#
list1 = ['test_cases.test_demo1.DemoTestCase1.test001', 'test_cases.test_demo2.DemoTestCase2.testaaa']
loader4 = unittest.defaultTestLoader.loadTestsFromNames(list1)
# 创建测试套件,收集测试类
suite = unittest.TestSuite()
suite.addTest(loader1)
suite.addTest(loader2)
suite.addTest(loader3)
suite.addTest(loader4)

# 创建执行器
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)
